package Policy;

// 抽象折扣策略接口
abstract class Discount {
    public abstract double calculate(double price);
}

// 学生折扣策略
class StudentDiscount extends Discount {
    @Override
    public double calculate(double price) {
        return price * 0.8; // 学生票8折
    }
}

// 儿童折扣策略
class ChildrenDiscount extends Discount {
    @Override
    public double calculate(double price) {
        if (price >= 20) {
            return price - 10; // 儿童票减免10元
        }
        return price; // 如果票价不足20元，不减免
    }
}

// VIP折扣策略
class VIPDiscount extends Discount {
    private int points = 0; // 积分

    @Override
    public double calculate(double price) {
        // 每次消费增加积分（这里简单实现，实际可能更复杂）
        points += (int)(price * 0.1);
        return price * 0.5; // VIP票半价
    }

    // 获取当前积分
    public int getPoints() {
        return points;
    }
}

// 电影票类
class MovieTicket {
    private double price;
    private Discount discount;

    public void setPrice(double price) {
        this.price = price;
    }

    public double getPrice() {
        if (discount != null) {
            return discount.calculate(price);
        }
        return price;
    }

    public void setDiscount(Discount discount) {
        this.discount = discount;
    }

    // 获取原始价格（无折扣）
    public double getOriginalPrice() {
        return price;
    }
}

// 测试类
public class CinemaTicketSystem {
    public static void main(String[] args) {
        // 创建电影票
        MovieTicket ticket = new MovieTicket();
        ticket.setPrice(100); // 设置票价为100元

        // 1. 测试学生票
        ticket.setDiscount(new StudentDiscount());
        System.out.println("学生票价格: " + ticket.getPrice());

        // 2. 测试儿童票
        ticket.setDiscount(new ChildrenDiscount());
        System.out.println("儿童票价格: " + ticket.getPrice());

        // 测试儿童票不足20元的情况
        ticket.setPrice(15);
        System.out.println("儿童票(15元)价格: " + ticket.getPrice());
        ticket.setPrice(100); // 恢复价格

        // 3. 测试VIP票
        VIPDiscount vipDiscount = new VIPDiscount();
        ticket.setDiscount(vipDiscount);
        System.out.println("VIP票价格: " + ticket.getPrice());
        System.out.println("VIP当前积分: " + vipDiscount.getPoints());

        // VIP再次购票积分增加
        ticket.setPrice(200);
        System.out.println("VIP票(200元)价格: " + ticket.getPrice());
        System.out.println("VIP当前积分: " + vipDiscount.getPoints());

        // 4. 测试无折扣票
        ticket.setDiscount(null);
        System.out.println("普通票价格: " + ticket.getPrice());
    }
}
